package com.sure.supermarketserver.stock.purchase.dao;

import com.sure.supermarketserver.stock.manage.BranchName;
import com.sure.supermarketserver.stock.purchase.CargoName;
import com.sure.supermarketserver.stock.purchase.Purchase;
import com.sure.supermarketserver.stock.purchase.PurchaseDto;
import com.sure.supermarketserver.stock.purchase.SupplierName;
import com.sure.supermarketserver.stock.supplier.Supplier;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PurchaseDao {

     //查询
     List<Purchase> findPurchaseList(PurchaseDto dto);
     //查询分店列表
     @Select("select distinct br_id from branch")
     List<String> getBranches();
     //查询供货商名称，用于生成下拉框
     @Select("select distinct su_name from supplier")
     List<SupplierName> findSupplierList();
     //查询货物名称，用于生成下拉框
     @Select("select distinct ca_name from cargo")
     List<CargoName> findCargoList();

     //增加
     @Insert("insert into import values (#{im_id},(select ca_id from cargo where ca_name=#{ca_name}),(select su_id from supplier where su_name=#{su_name}),#{im_num},#{im_day},#{im_price},#{im_date})")
     void insertIntoImport(PurchaseDto dto);
     //同时在仓库中添加商品信息
     void insertIntoGoods(PurchaseDto dto);
     @Update("update goods set go_num=#{im_num} where im_id=#{im_id} and br_id='00'")
     void updateGoodNum(PurchaseDto dto);


     //修改
     void updateImport(PurchaseDto dto);
     void updateGoods(PurchaseDto dto);

     //删除
     @Delete(" delete from goods where im_id = #{im_id};")
     void deleteGoods(Integer id);
     @Delete("delete from import where im_id = #{im_id};")
     void deleteImport(Integer id);

     //用于自动生成进货编号
     @Select("select lpad(ifnull(max(convert(substring(im_id,7,3),signed)),0)+1,3,'0')  from import where im_id like concat(#{s},'%')")
     String findNewNum(String s);



}
